Skip to content

Comments

interfaces/cantact: Handle None timeout by setting to 0xFFF...#2026

Open
BenGardiner wants to merge 1 commit intohardbyte:mainfrom
BenGardiner:patch-1
Open

interfaces/cantact: Handle None timeout by setting to 0xFFF...#2026
BenGardiner wants to merge 1 commit intohardbyte:mainfrom
BenGardiner:patch-1

Conversation

@BenGardiner
Copy link
Contributor

Summary of Changes

There are definitely cases of client code that end up passing timeout=None to _recv_internal(). Several other interfaces/*.py are prepared for this e.g. canalystii usb2can canlib_vcinpl2 gs_usb.py

For cantact I think the right thing to do is set default timeout to 0 if None is provided.
There are definitely cases of client code that end up passing timeout=None to _recv_internal(). Several other interfaces/*.py are prepared for this e.g. canalystii usb2can canlib_vcinpl2 gs_usb.py

For cantact I think the right thing to do is set default timeout to 0 if None is provided.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

@zariiii9003
Copy link
Collaborator

But None means it should block indefinitely until a message is received.

The cantact lib calls recv_timeout(std::time::Duration::from_millis(timeout_ms) under the hood. I think it would be better to set timeout to a very large number (2**64 - 1) instead of 0.

@zariiii9003
Copy link
Collaborator

The usb2can implementation seems correct to me. If our timeout is None, then CanalBlockingReceive is called with 0, which means "wait forever" according to the documentation.

The gs_usb implementation seems wrong indeed.

The candle_bus implementation also seems incorrect, but that's not part of this repo.

@BenGardiner
Copy link
Contributor Author

BenGardiner commented Feb 22, 2026

thank you @zariiii9003 .

I fixed this change to cantact with a force-push.

I made this BIRLab/python-can-candle#5 for python-can-cantact

I am not sure how to fix gs-usb and also these days I find it hard to test it since it requires libusbK. I don't use it almost ever since the cantact (and now python-can-candle) drivers work with the exact same devices...

@zariiii9003
Copy link
Collaborator

Thank you! Please add a short news fragment and i'll merge.

Regarding gs-usb: it seems to be similar to usb2can, to block forever the read function needs to be called with 0:
https://github.com/jxltom/gs_usb/blob/510bfeb960cb39d8a98514e3b95132bb51ec9b77/gs_usb/gs_usb.py#L168

@BenGardiner BenGardiner changed the title interfaces/cantact: Handle None timeout by setting to 0 interfaces/cantact: Handle None timeout by setting to 0xFFF... Feb 23, 2026
BenGardiner added a commit to BenGardiner/python-can that referenced this pull request Feb 23, 2026
pass '0' when timeout=None (as proposed by @zariiii9003
 in hardbyte#2026 (comment))
BenGardiner added a commit to BenGardiner/python-can that referenced this pull request Feb 23, 2026
pass '0' when timeout=None (as proposed by @zariiii9003
 in hardbyte#2026 (comment))
BenGardiner added a commit to BenGardiner/python-can that referenced this pull request Feb 23, 2026
pass '0' when timeout=None (as proposed by @zariiii9003
 in hardbyte#2026 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants